package com.eastfair.transport.controller;

import com.eastfair.annotation.annotation.log.SysLog;
import com.eastfair.annotation.annotation.security.PreAuth;
import com.eastfair.core.base.R;
import com.eastfair.core.exception.BizException;
import com.eastfair.transport.service.TransportServiceBookingService;
import com.eastfair.venueservice.dto.ServiceBookingDTO;
import com.eastfair.venueservice.dto.ServiceBookingQuery;
import com.eastfair.venueservice.vo.ServiceBookingVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.constraints.NotEmpty;
import java.util.List;


/**
 * <p>
 * 前端控制器
 * 主运服务预订
 * </p>
 *
 * @author ln
 * @date 2022-10-08
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/transportServiceBooking")
@Api(value = "TransportServiceBooking", tags = "主运服务预订")
@PreAuth(replace = "transport:transportServiceBooking:")
public class TransportServiceBookingController{

    @Resource
    private TransportServiceBookingService transportServiceBookingService;

    /**
     * 删除预定服务
     * @param serviceBookingDTO serviceBookingDTO
     * @return R<Boolean>
     */
    @ApiOperation(value = "删除预定服务")
    @SysLog("删除预定服务")
    @PostMapping(value = "/delServiceBooking")
    public R<Boolean> delServiceBooking(@RequestBody ServiceBookingDTO serviceBookingDTO){
        try {
            return R.success(transportServiceBookingService.delServiceBooking(serviceBookingDTO));
        } catch(BizException biz) {
            return R.fail(biz);
        }
    }

    /**
     * 添加服务预订(主运)
     * @param serviceBookingDTO serviceBookingDTO
     * @return R<Boolean>
     */
    @ApiOperation(value = "添加服务预订(主运)")
    @SysLog("添加服务预订")
    @PostMapping(value = "/addServiceBookingOfTransport")
    public R<Boolean> addServiceBookingOfTransport(@RequestBody @Validated @NotEmpty List<ServiceBookingDTO> serviceBookingDTO){
        try {
            return R.success(transportServiceBookingService.addServiceBookingOfTransport(serviceBookingDTO));
        } catch(BizException biz) {
            return R.fail(biz);
        }
    }

    /**
     * 服务预订列表（主运）
     *
     * @param serviceBookingQuery 服务预订列表（主运）
     * @return R
     */
    @ApiOperation(value = "服务预订列表（主运）", notes = "服务预订列表（主运）")
    @PostMapping("/queryServiceBookingListOfTransport")
    public R<List<ServiceBookingVO>> queryServiceBookingListOfTransport(@RequestBody ServiceBookingQuery serviceBookingQuery) {
        log.info("queryServiceBookingListOfTransport - 服务预订列表 serviceBookingQuery={}", serviceBookingQuery);
        return R.success(transportServiceBookingService.queryServiceBookingListOfTransport(serviceBookingQuery));
    }
}
